----------------------------------------------
I  GREYSCALE THINGS VERSION 0.8 BETA         I
----------------------------------------------
I  by DANIEL DUBE                            I
----------------------------------------------

IF YOU USE ANYTHING OF THAT, IT IS ON YOUR OWN RISK !!!

files:
	grey_int.asm
	grey_spr.asm
	grey_pic.asm
	grey_use.asm (simple demo for this library)
	grey_lib.txt (this file)



ok, here are some very usefull routines if you want to code some 
greyscale programs on your ti-83:

	A. interupt greyscale engine
	B. routine to put greyscale sprites
	C. routines to save/recall the background of sprites
	D. routine to put whole greyscale pics
	E. program to convert 256-color bitmaps to greypics for this routine
	F. fill_page (clear screen)
	

ALL ROUTINES BASED ON THE INTERUPT GREY ENGINE (A) AND CAN ONLY BE USED AFTER INITILIZING
THE INTERUPT !!!!!!!!!

A. interupt greyscale engine:
---------------------------------
grey_int.asm

ok, this routine is loaded in memory, and uses the interupt methode to load frequently 2 different screen pages in the lcd. it takes 3 cycles where the first pic is load for one and the second pic for two cycles and this very fast. so the effect is, as you surly know, that your ti83 gets 4 colors (white,grey,dark grey,black). experiment with the contrast if it looks
like only 3 or less colors.

i think this routine i will not change anymore, perhaps one little idea i will add, but at all there shouldn't be bugs anymore.

the routine copy itself in the apd-memory page. so don't use this memory page while the engine is running. this will cause surley a hang on of your calc. the system of the calc shouldn't use this memory during the engine is active, because apd is disabled, but the calc interupt is still running, so you can still use the system keyroutines or something. and don't forget: the calc becomes slower while the engine is running (because 786 bytes of data are sent direct to lcd in background, and that around 100 times per second !!!)

activate this engine is simple: just call init_int and it is started. the routine creates 2 different program files ('z_greya','z_greyb') both 786 bytes big. there are the two screen pages stored. the memory pointer of the beginning of this pages are stored in [int_buffer] (first)
[int_buffer+2] (second page). the engine uses the y-increment mode, so if you want the offset of a screenposition use:

@mem1=[int_buffer]+(x div 8)*64+y
@mem2=[int_buffer+2]+(x div 8)*64+y
(look explaination of get_offset !!!)

so if you want to have a white pixel clear the bits in both pages, if you want to have a grey set it only in the first, for a dark grey only in the second and for a black in both pages.

example:
-------

x=22
y=32
color=grey

offset=(x div 8)*64+y=(22 div 8)*64+32=2*64+32=160
@mem1=[int_buffer]+offset
@mem2=[int_buffer]+2+offset
bit=8- (22 mod 8)=2

so we have to modify the 2. bit of the byte @mem1 and @mem2 :

	@mem1		@mem2
	--------	--------
before	10001000	00010001
pixel	00000010	00000000
after	10001010	00010001

the result is a grey pixel at point (22;32). kind of confused? i cant explain more detailed, best is to email me your questions.



and if you want to deinstall the engine just call deinit_int (the 2 program files will be (deleted).
NOTE: USE deinit_int at EVERY END of your program, because the ti-shell can't use grayscales!!!!

so this is all to explain... questions ? so email (look below for adress).



B. routine to put greyscale sprites
--------------------------------------
grey_spr.asm

the sprite should be two 8x8 bit data blocks. all bits are set in the first block cause a grey, all bits in the second a dark grey and in both a black pixel. if no bit is set on one position it will display the background.

example:
--------
	.db %00011000
	.db %00111100
	.db %01000010
	.db %11011011
	.db %11011011
	.db %01000010
	.db %00111100
	.db %00011000

	.db %00011000
	.db %00111100
	.db %01111110
	.db %11100111
	.db %11100111
	.db %01111110
	.db %00111100
	.db %00011000


the result is something like a spinned cube.


	b	x-coordinate
	c	y-coordinate
	hl	memory
	
to use the routine put the x coordinate in b the y in c and the memory adress of the sprite in hl. and then call putsprite ! but be carefull ! there is no clipping !!!!!! (i think i will add this in future). of course, i know that this routine is relative slow. it puts around 100 sprites per second with enabled interupt. if you have many sprites to draw and you can disable interupt (di-command) and enable (ei) it after drawing. so it gets much faster. i think i will optimize the routine, or do it yourself... but i think it isn't easy to understand the whole code.

this is all to say about.


C. routines to save/recall the bg of sprites
----------------------------------------------
grey_spr.asm

input: 	b=x coordinate
	c=y coordinate
	de=adress of 32 bytes buffer memory

the two routines are very simple. the first one stores 16x8 bytes of both mem. pages of screen in a buffer and the second redraw it from the buffer back to screen. you can use it if you want to have a moved sprite on a fixed background. just call store_bg before drawing the sprite and if you want to remove the sprite and you want to have the background you had before drawing the sprite, just call recall_bg.
note: the x y values have to be the same when you use this method. (else the background you copyed from pos. (3,4) will be drawn back to pos. (20,10).)


D. routine to put whole greyscale pics
-----------------------------------------
grey_pic.asm

the pics should have max size of 96x64 pixels. the pic datas are aranged like this for example:

	.db x,y
	.db datas of page1
	.db datas of page2

x: is the x size of the pic in byte (pixel size div 8 +1)
y: is the y size of the pic

so for a 96x64 byte pic use:

	.db 12,64

the datas are aranged like the screen-files (description look point A.)

to use it just load the memory offset of the pic in hl register and call copy_pic.
to convert a BITMAP to datas look next point!


E. program to convert 256-color bitmaps to greypics for this routine
-----------------------------------------------------------------------

at first you need a 256 color bitmap with max size of 96x64 pix (smaller is ok). then you have
to start:

bmp83_i.exe $bmp

$bmp is the filename of the bitmap!

at first after the start there are displayed the filenames again, then press a key and there you will have a graphic screen with 4 pics.
1 pic: page 1 of grey pic
2.pic: page 2 of grey pic
3.pic: so the pic will look on your calc
4.pic: so the pic looks in orginal

then the numbers:
the first 3 numbers are the ranges of the different colors (white,grey,black)
the other 2 numbers display the size the pic will have on your calc in bytes ! (norm. unintresting)

you can modify the ranges by using the key '1','2' or '3' and then the '+' or '-' key.

with the range you can adjust the range in which a pixel is taken as black,grey,dark grey,white. so all colors of your original pics are under the black range are drawn as black, all between the black and grey as grey, between grey and white -->dark grey, above white--> white. just experiment with this ranges, and you will fast get the result you want.

when you have the pic you want, press space, and the datas of th pic are stored in the textfile, so you only have to copy the text from the file in your source code. 



F. fill_page
-------------------
if you want to have a clear screen befor drawing (i think you want) use the fill_page routine (grey_spr.asm), just but the bit pattern (%00000000 for clear) in a and the adress of the memory page ([int_buffer] / [int_buffer+2]) in hl. call fill_page and you will have your screen filled with the pattern you stored in a. (you have to do this one time for every page (so 2 times at all).)



-------------------------------------------
so, this is all for now. of course there will be some bugs in the code. and if you find some, tell it to me! if you have some questions because my explainations weren't clear enough then let me know too. if you want to use something in your own projects, do it, but please give me credits (it was many work to write and test this routines) and if you optimize something or modify, please send a copy of the new source code to me...
there will surely follow some updates of the progs, this is only something like a BETA VERSION! 
oh, i developed all this stuff with ANOVA as shell, so if you use sos or something it might don't work, but try it !


CONTACT: 
	mail:	ich_fress_kleine_kinder@gmx.de
	icq:	63533869
	name:	daniel dube


special thanx to James Matthews (asm83 guru) and ian graf because i learned all the things i know about the direct lcd communication and the calc system (interupt,...) from them. 
also thanx to flori z. for bug report.

hey Cameron McCormack, your chaos assembler is great !!!!!


DON'T FORGET: JESUS IS JUST A LIE OF THE CHURCH TO EARN MONEY !!!!


written 21.02.2001 by daniel dube
update 14.06.2001